﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PMPUtils.DB;

namespace PMPUtils.Maintenance
{
    public class ChecklistMaintain
    {
        public static bool IsChecklistAlreadyExists(String component, String item)
        {
            String strQuery = "select count(id) exist from checklist where component = '" + component + "' and item = '" + item + "'";
            DBOperator localOperator = new DBOperator(DBConfigurations.LOCAL_CONNECTION_STRING);
            DataTable dtExists = localOperator.Read(strQuery);

            bool isExists = false;

            foreach (DataRow row in dtExists.Rows)
            {
                if (row["exist"] != DBNull.Value)
                {
                    if (Convert.ToInt32(row["exist"]) >= 1)
                    {
                        isExists = true;
                    }
                }
            }

            return isExists;
        }

        public static void AddChecklist(String compment, String item, String itemDesc,
            String executionType, String executationID)
        {
            String strInsert = "insert into checklist (component, item, item_desc, exe_type, exe_id) values ( " +
                "'" + compment + "', '" + item + "', '" + itemDesc + "', '', '')";
            DBOperator localOperator = new DBOperator(DBConfigurations.LOCAL_CONNECTION_STRING);
            localOperator.Update(strInsert);
        }
    }
}
